from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():
    # 声明参数
    uav_namespace_arg = DeclareLaunchArgument(
        'uav_namespace',
        default_value='uav_swarms',
        description='Namespace for UAV swarms.'
    )

    vehicle_type_arg = DeclareLaunchArgument(
        'vehicle_type',
        default_value='drone',
        description='Type of vehicle.'
    )

    vehicle_num_arg = DeclareLaunchArgument(
        'vehicle_num',
        default_value="3",
        description='Number of vehicles.'
    )
    
    left_x_arg = DeclareLaunchArgument(
        'left_x',
        default_value='80.0',
        description='Width of the area.'
    )

    left_y_arg = DeclareLaunchArgument(
        'left_y',
        default_value='-100.0',
        description='Height of the area.'
    )

    width_arg = DeclareLaunchArgument(
        'width',
        default_value='300.0',
        description='Width of the area.'
    )

    height_arg = DeclareLaunchArgument(
        'height',
        default_value='400.0',
        description='Height of the area.'
    )


    spacing_arg = DeclareLaunchArgument(
        'spacing',
        default_value='50.0',
        description='Spacing between drones.'
    )

    gap_arg = DeclareLaunchArgument(
        'gap',
        default_value='10.0',
        description='Gap between formations.'
    )

    # 创建节点
    communication_multirotor_node = Node(
        package="quyufugai",
        executable="quyufugai_node",
        name="quyufugai_node",
        output="screen",
        emulate_tty=True,
        parameters=[
            {"uav_namespace": LaunchConfiguration('uav_namespace')},
            {"vehicle_num": LaunchConfiguration('vehicle_num')},
            {"vehicle_type": LaunchConfiguration('vehicle_type')},
            {"left_x": LaunchConfiguration('left_x')},
            {"left_y": LaunchConfiguration('left_y')},
            {"width": LaunchConfiguration('width')},
            {"height": LaunchConfiguration('height')},
            {"spacing": LaunchConfiguration('spacing')},
            {"gap": LaunchConfiguration('gap')},
        ]
    )

    # 创建并返回 LaunchDescription
    return LaunchDescription([
        uav_namespace_arg,
        vehicle_type_arg,
        vehicle_num_arg,
        left_x_arg,
        left_y_arg,
        width_arg,
        height_arg,
        spacing_arg,
        gap_arg,
        communication_multirotor_node
    ])
